cmake_minimum_required(VERSION 3.4.1)

include_directories(${ANDROID_NDK}/toolchains/llvm/prebuilt/darwin-x86_64/)
# include_directories(External/include)

find_library(log-lib log)

set(EXT_LIBS_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp/External/libs)
message(${EXT_LIBS_DIR})

add_library(ASSIMP_LIB SHARED IMPORTED)
set_target_properties(ASSIMP_LIB PROPERTIES IMPORTED_LOCATION ${EXT_LIBS_DIR}/${ANDROID_ABI}/libassimp.so)


MESSAGE( STATUS "ASSIMP_LIB = ${ASSIMP_LIB}.")
if (NOT ${ASSIMP_LIB})
       message(FATAL_ERROR "ASSIMP_LIB not found!")
endif()

FILE(GLOB RENDER_SRC_FILES Render/*.cpp Render/*.h Render/MeshModel.cpp Render/MeshModel.h Render/Bone.h Render/Bone.cpp Render/RenderItemOpaque.h Render/RenderItemOpaque.cpp Render/RenderItemSkinnedMeshOpaque.h Render/RenderItemSkinnedMeshOpaque.cpp Render/GameObject.h Render/GameObject.cpp)
add_library(render-lib SHARED ${RENDER_SRC_FILES})

FILE(GLOB PHY_SRC_FILES Physics/*.cpp Physics/*.h)
add_library(phy-lib SHARED ${PHY_SRC_FILES})
target_link_libraries(phy-lib ${log-lib})
target_include_directories(phy-lib PRIVATE glm)
target_include_directories(phy-lib PRIVATE Render)

FILE(GLOB UTILS_SRC_FILES Utils/*.cpp Utils/*.h)
add_library(utils-lib SHARED ${UTILS_SRC_FILES})

add_library(native_app_glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

target_include_directories(render-lib PRIVATE ${ANDROID_NDK}/sources/android/native_app_glue)
target_include_directories(render-lib PRIVATE glm)
target_include_directories(render-lib PRIVATE Physics)
target_include_directories(render-lib PRIVATE Utils)
target_include_directories(render-lib PRIVATE External/include/)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror")
set(CMAKE_SHARED_LINKER_FLAGS  "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

target_link_libraries(
        render-lib
        phy-lib
        utils-lib
        ASSIMP_LIB
        android
        native_app_glue
        EGL
        GLESv3
        ${log-lib}
        )